package org.example.elm_xiangmu.service.impl;


import org.example.elm_xiangmu.mapper.OrderDetailetMapper;
import org.example.elm_xiangmu.po.Food;
import org.example.elm_xiangmu.po.OrderDetailet;
import org.example.elm_xiangmu.service.FoodService;
import org.example.elm_xiangmu.service.OrderDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderDetailServiceImpl  implements OrderDetailService {
    @Autowired
    OrderDetailetMapper orderDetailetMapper;
    @Autowired
    FoodService foodService;
    void saveOrderDetailet(OrderDetailet orderDetailet) {
        orderDetailetMapper.saveOrderDetailet(orderDetailet);
    }

    List<OrderDetailet> getOrderDetailetByOrderId(Integer orderId) {
        List<OrderDetailet> orderDetailetList =  orderDetailetMapper.getOrderDetailetByOrderId(orderId);
        for (OrderDetailet orderDetailet : orderDetailetList) {
            Food food = foodService.getByFoodId(orderDetailet.getFoodId());
            orderDetailet.setFood(food);
        }
        return orderDetailetList;
    }


}
